<%@page contentType="text/html;charset=utf-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>   
<script type="text/javascript">
function sys_onrolecheck(role)
{
    var userrole = document.getElementById("rl_value");
    if (userrole.value == null || userrole.value == "")
    {
        userrole.value = 0;
    }
    /*alert(userrole.value);*/
    if (role.checked == true)
        userrole.value = parseInt(userrole.value) + parseInt(role.value);
    else
        userrole.value = parseInt(userrole.value) - parseInt(role.value);       
    /*alert(userrole.value);*/
}
function sys_saverole(type)
{
    var rl_id = document.getElementById("rl_id").value;
    var rl_name = document.getElementById("rl_name").value;

    if (/*rl_id == null || rl_id == "" 
        || */rl_name == null || rl_name == ""/*
        || rl_value == null || rl_value == ""*/)
    {
        alert("信息不完整！");
        return false;
    }

    var rl_value= new Array(128) ;
    var inputel =  document.getElementsByTagName("input");
    
    for (var i = 0; i < 128; i++)
    {
    	rl_value[i]="0";
    }
    
   for(var i=0;i<inputel.length;i++) 
   { 
       if(inputel[i].type=="checkbox")
       {
           if(inputel[i].checked)
           {
               if(inputel[i].id=="role_keys")
               {
            	   rl_value[(inputel[i].value-1)]="1";
               }
           }
       }
   } 
   
    if (!confirm("确定继续？"))
    {
        return false;
    }
    var url = "rs/role/save.do";
    var content = "type=" + type
                + "&role.id=" + rl_id
                + "&role.name=" + rl_name
                + "&role.value=" + rl_value.join("");
    /*alert(content);*/
    var objectid = "sys_role";
    sendXMLHttpRequest(url, content, objectid); 
}
</script>
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="5"></td>
    <td>   
  <form id="myform">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td colspan="3">
        <table width="100%"  border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><img src="images/table_top_left.jpg" width="20" height="15" /></td>
            <td><img src="images/table_top_bg.jpg" width="770" height="15"/></td>
            <td align="right">
              <img src="images/table_top_right.jpg" width="20" height="15" /></td>
          </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td height="25" colspan="3" class="table_blue">
        <strong><img src="images/dot.jpg" width="13" height="9">角色信息</strong></td>
    </tr> 
    <tr>
      <td class="table_w1" width="20%">&nbsp;<font color="red">(*)</font>ID：</td>
      <td class="table_w2" width="80%" colspan="2">&nbsp;
        <input id="rl_id" type="text" size="60" 
          value="<s:property value="role.id" />" readonly="readonly" /></td>
    </tr>
    <tr>
      <td class="table_w1" width="20%">&nbsp;<font color="red">(*)</font>名称：</td>
      <td class="table_w2" colspan="2">&nbsp;
        <input id="rl_name" type="text" size="60" 
          value="<s:property value="role.name" />" /></td>
    </tr>
    <s:if test="menus.size()>0" >    	
    <tr>
      <td class="table_w1" width="20%" rowspan="<s:property value="%{getMenuCount()+1}" />" >
      &nbsp;<font color="red">(*)</font>权限：</td>
    </tr>
    <s:iterator value="menus" status="stat">
    <tr>
      <td class="table_w2" rowspan="<s:property value="submenu.size()+1" />" 
          width="20%" >&nbsp;
        <input type="checkbox" id="role_keys" value="<s:property value="index" />"
           <s:if test="role.value.charAt(index-1)=='1'">checked="checked"</s:if> >
           &nbsp;<s:property value="title" />
      </td>
    </tr>
    <s:if test="submenu.size()>0">
    <s:iterator value="submenu" status="stat1">
    <tr>
      <td class="table_w2"
          width="20%" >&nbsp;
        <input type="checkbox" id="role_keys" value="<s:property value="index" />"
           <s:if test="role.value.charAt(index-1)=='1'">checked="checked"</s:if> >
           &nbsp;<s:property value="title" />
      </td>
    </tr>
    </s:iterator>
    </s:if>
    </s:iterator>
    </s:if>
    <tr>
      <td colspan="3" class="table_w1" align="center">
        <s:if test="type.equals('insert')" >
        <button id="btn2" dojoType="dijit.form.Button"
            onclick="return sys_saverole('insert');">添加</button>
        </s:if>
        <s:else>
        <button id="btn2" dojoType="dijit.form.Button"
            onclick="return sys_saverole('update');">修改</button>
        <s:if test="role.roleId!=1">
        &nbsp;&nbsp;        
        <button id="btn3" dojoType="dijit.form.Button"
            onclick="return sys_saverole('delete');">删除</button>
        </s:if>
        </s:else>
      </td>      
    </tr>
    <tr> 
      <td colspan="3" background="images/table_bom_bg.jpg">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td><img src="images/table_bom_left.jpg" width="20" height="15"></td>
          <td></td>
          <td align="right">
            <img src="images/table_bom_right.jpg" width="20" height="15"></td>
        </tr>
        </table>
      </td>
    </tr>
  </table>  
  </form>
  </td>
  <td width="5"></td>
  </tr>
  </table>